package org.example.librarydemo;

import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public String login(String userName, String password, HttpSession session) {
        //1、参数校验
        //2、验证用户名和密码
        //3、存session
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return "用户名或密码不能为空";
        }

        if(!"zhangsan".equals(userName) || !"123456".equals(password)) {
            return "用户名或密码错误";
        }

        //没问题就存储session
        session.setAttribute("userName", userName);
        return "login";
    }
}
